package awt;
import java.awt.Button;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class AWTCloseExample extends Frame {
	
	public AWTCloseExample() {
		setTitle("MyFrame"); 
		setSize(400, 100); 
		addWindowListener(new CloseEventHandler()); 
		setVisible(true); 
	}

	class CloseEventHandler extends WindowAdapter {
		public void windowClosing(WindowEvent e) {
			e.getWindow().dispose(); 
			System.exit(0); 
		}
	}

	public static void main(String args[]) {
		AWTCloseExample ctf = new AWTCloseExample();
		ctf.setVisible(false);
		ctf.dispose();
		ctf.add(new Button());
		ctf.setVisible(true);
		
	}
}

